var utils = require('../../../utils/util.js')
var c = require('../../../utils/config.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bank_phone:"",
        bank_name:"",
        bank_no:"",
        username:"",
        wangdian: "",
        ishide:""
    },
    submit:function(){
        var bank_phone = this.data.bank_phone;
        var bank_name = this.data.bank_name;
        var bank_no = this.data.bank_no;
        var username = this.data.username;
        var wangdian = this.data.wangdian;
        var token = wx.getStorageSync("userinfo").wap_token;
        if (bank_name == ""){
            utils.errMsg("银行卡信息错误");
            return;
        }
        var data = {
            url: "/wsgoods/userbank/add",
            token: token,
            type:0,
            bank_no: this.data.bank_no,
            bank_name: this.data.bank_name,
            bank_phone: this.data.bank_phone,
            username: this.data.username,
            bank_wangdian: this.data.wangdian
        };
        utils.request(data).then(function (res) {
            if (res.code == 0) {
                utils.sucMsg("绑定成功");
                setTimeout(function(){
                    wx.navigateBack({
                        delta: 1
                    })
                },1500);
            } else {
                utils.errMsg(res.msg);
            }
        });
    },
    editPhone:function(e){
        var bank_phone = e.detail.value;
        this.setData({
            bank_phone: bank_phone
        })
    },
    editbankNo: function (e) {
        var bank_no = e.detail.value;
        this.setData({
            bank_no: bank_no
        })
    },
    editUsername: function (e) {
        var username = e.detail.value;
        this.setData({
            username: username
        })
    },
    editwangdian: function (e) {
        var wangdian = e.detail.value;
        this.setData({
            wangdian: wangdian
        })
    },
    /**
     * 验证银行
     */
    getBank:function(){
        var that = this;
        var token = wx.getStorageSync("userinfo").wap_token;
        var data = {
            url: "/wsgoods/userbank/getBankInfo",
            token: token,
            bank_no: this.data.bank_no,
        };
        utils.request(data).then(function (res) {
            if (res.code == 0) {
                var data = res.data;
                that.setData({
                    bank_name: data.bak
                });
            } else {

            }
        });
    }

})